import os,shlex,subprocess
# os.system(command)
# os.system("cmd")

# cmd = 'cmd'
# res = os.popen(cmd)
# output_str = res.read()   # 获得输出字符串
# print(output_str)

# p = subprocess.Popen('pause', shell=True,
#                      stdout=subprocess.PIPE,
#                      stderr=subprocess.STDOUT,
#                      encoding='gb2312');

version='0.1'
print("panda "+version+" 版")
print("输入\"help()\"获取更多信息.")

while True:
	text = input(">> ").strip();

	if text:
		# tokenize the command, double quotes taken into account
		# toks = shlex.split(command)
		# print(toks);
		# if toks[0] == "cd" and len(toks)==2:
		#     print(9);
		#     newdir = toks[1]
		#     try:
		#         os.chdir(newdir)
		#     except Exception as e:
		#         print("Failed {}".format(str(e)))
		#     else:
		#         print("changed directory to '{}'".format(newdir))
		# else:

		p = subprocess.Popen('dir',shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,encoding='gb2312');

		if text=="help()":
			print(f'''
			欢迎使用panda {version}的帮助工具！

			如果这是您第一次使用panda,那么您肯定应该检查一下互联网上的教程
			https://docs.python.org/3.10/tutorial/.输入任何模块、关键字或主
			题的名称以获得写作帮助panda程序和使用panda模块.要退出此帮助实
			用程序并返回到解释器,只需键入"quit".

			要获取可用模块`关键字`符号或主题的列表,请键入"模块"`"关键词"`"符
			号"或"主题".每个模块也有用一行文字概括它的作用;列出其名称的模块或
			摘要包含给定的字符串,如"垃圾邮件",键入"模块垃圾邮件".
			'''.format(version));
		elif text=='len':
			print('关于内置函数len的帮助：');
			print('len(value); 获取变量长度');
		elif text=='print':
			print('关于内置函数print的帮助：');
			print('print(value); 获取变量长度');

		# if text == "help()":
		#     text = input("help> ").strip();

		rc=p.wait()
		if rc:
			print("Command failed returncode {}".format(rc))





